<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAsyncTaskTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('async_task', function (Blueprint $table) {
            $table->increments('id');
            $table->string('key',32)->comment('唯一值')->unique();
            $table->string('type',32)->comment('任务类型');
            $table->string('name',32)->comment('任务名');
            $table->string('params',1023)->comment('任务参数')->nullable();
            $table->text('result')->comment('任务结果')->nullable();
            $table->text('runtime')->comment('运行时记录，比如进度')->nullable();
            $table->tinyInteger('state')->default(0)->comment('任务状态，0初始，1成功，-1失败');
            $table->unsignedInteger('uid')->default(0)->comment('用户id');
            $table->unsignedInteger('pid')->default(0)->comment('执行任务的进程id');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('async_task');
    }
}
